package com.eigaland.change_machine.business.splash

import android.view.View
import androidx.navigation.Navigation
import com.eigaland.change_machine.APP
import com.eigaland.change_machine.R
import com.eigaland.change_machine.business.home.HomeAct
import com.eigaland.change_machine.business.home.HomeActVM
import com.eigaland.change_machine.business.login.LoginFragment
import com.eigaland.change_machine.business.movielist.MovieListFragment
import com.eigaland.change_machine.business.setup_account.SetUpAccountFragment
import com.eigaland.change_machine.databinding.FragmentLoginBinding
import com.eigaland.change_machine.util.ProgressDialogManager
import com.eigaland.change_machine.util.UserManager
import com.eigland.eigaland_lib.base.BaseFragment
import com.eigland.eigaland_lib.base.BaseLazyFragment
import com.eigland.eigaland_lib.model.Cinema
import me.yokeyword.fragmentation.ISupportFragment
import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator
import me.yokeyword.fragmentation.anim.DefaultVerticalAnimator
import me.yokeyword.fragmentation.anim.FragmentAnimator
import movie6.posprintercept2.extensions.getCinemaId
import movie6.posprintercept2.extensions.getDeviceSec
import movie6.posprintercept2.extensions.getToken

public class SplashFragment : BaseLazyFragment<HomeActVM, FragmentLoginBinding>() {



    override fun initVM() {
        //映画ランド有料会員割引
        view?.postDelayed({
            ProgressDialogManager.dismissDialog(requireContext())
            if(context?.getDeviceSec().isNullOrEmpty()) {
                supportDelegate.replaceFragment(LoginFragment(),false)
            } else if(context?.getToken().isNullOrEmpty()) {

                supportDelegate.replaceFragment(SetUpAccountFragment(), false)

            } else if(context?.getToken() != null) {
                supportDelegate.replaceFragment(MovieListFragment(), false)

                UserManager.cinemaId = requireContext().getCinemaId()
            }
        },2000)
    }

    override fun onCreateFragmentAnimator(): FragmentAnimator {
        return DefaultHorizontalAnimator()
    }

    override fun setUpViewData(view: View) {
        ProgressDialogManager.showDialog(requireContext())

     }

    override fun setLayoutId() = R.layout.fragment_splash
}